import json
import requests

# url = "https://httpbin.org/get"
# # 发起请求，获取响应
# res = requests.get(url)
# # 直接将响应结果转换为json对象
# data = res.json()
# print(type(data),data['headers']['User-Agent'])

# url = "https://www.baidu.com/robots.txt"
# res = requests.get(url)
# print(res.text)

# url = "http://httpbin.org/get"
# res = requests.get(url)
# print(res.text)
# data = json.loads(res.text)
# print(type(data), data['headers']['User-Agent'])

# # content手动解码
# url = "http://www.baidu.com"
# res = requests.get(url)
# # 手动解码
# data = res.content.decode()
# print(type(data),data)

 # url = "http://httpbin.org/get"
# res = requests.get(url)
# data = json.loads(res.content.decode())
# print(data['headers']['User-Agent'])

# url = "https://haowallpaper.com/link/common/file/previewFileImg/16563360456428928"
# res = requests.get(url)
# data = res.content
# with open('img1.jpg','wb') as f:
#     f.write(data)


response = requests.get("http://books.toscrape.com")
if response.ok:
    print(response.text)
else:
    print("请求失败")